﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class ProductsDAO:IData<Products> 
 	{
		public ProductsDAO(String myconnecString) : base(myconnecString) { }

		public override int OnSubmit(Products item, int t) {
			 return connec.ExecuteNonQuery("sp_Products", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + Products.c_id, item.id), new SqlParameter("@" + Products.c_categoryId, item.categoryId),
				 new SqlParameter("@" + Products.c_productName, item.productName), new SqlParameter("@" + Products.c_description, item.description),
				 new SqlParameter("@" + Products.c_create_on, item.create_on), new SqlParameter("@" + Products.c_price, item.price),
				 new SqlParameter("@" + Products.c_updatePriceLast, item.updatePriceLast), new SqlParameter("@" + Products.c_pathImage, item.pathImage),
				 new SqlParameter("@" + Products.c_isActive, item.isActive)); 
		}

		public override Products GetItem(IDataReader dr)
		{
			Products obj = new Products();
			obj.id = Convert.ToInt64(dr[Products.c_id]);
			obj.categoryId = Convert.ToInt64(dr[Products.c_categoryId]);
			obj.productName = Convert.ToString(dr[Products.c_productName]);
			obj.description = Convert.ToString(dr[Products.c_description]);
			obj.create_on = Convert.ToDateTime(dr[Products.c_create_on]);
			obj.price = Convert.ToDecimal(dr[Products.c_price]);
			obj.updatePriceLast = Convert.ToDecimal(dr[Products.c_updatePriceLast]);
			obj.pathImage = Convert.ToString(dr[Products.c_pathImage]);
			obj.isActive = Convert.ToInt32(dr[Products.c_isActive]);
			return obj;
		}

		public override List<Products> GetAll()
		{
			return GetAll("select * from " + Products.b_Products, CommandType.Text);
		}

		public override Products GetItemById(object id)
		{
			throw new NotImplementedException();
		}

	}

 }
